package com.elitel.frame.web.cfgtablefield.controller;

import com.elitel.common.core.domain.JsonResult;
import com.elitel.frame.web.cfgtablefield.entity.CfgTableField;
import com.elitel.frame.web.cfgtablefield.entity.CfgTableFieldVO;
import com.elitel.frame.web.cfgtablefield.service.CfgTableFieldService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 元数据-字段信息表(CfgField)表控制层
 *
 * @author makejava
 * @since 2025-05-19 16:20:52
 */
@RestController
@RequestMapping("cfgTableField")
public class CfgTableFieldController {
    /**
     * 服务对象
     */
    @Resource
    private CfgTableFieldService cfgTableFieldService;

    @GetMapping("listByTableId")
    public JsonResult<List<CfgTableFieldVO>> listByTableId(String tableId) {
        CfgTableField cfgTableField = new CfgTableField();
        cfgTableField.setDtConfigId(tableId);
        List<CfgTableField> list = cfgTableFieldService.list(cfgTableField);
        List<CfgTableFieldVO> resList = list.stream().map(item -> {
            CfgTableFieldVO res = new CfgTableFieldVO();
            res.setFieldId(item.getGuid());
            res.setFieldCode(item.getDfName());
            res.setFieldName(item.getDfNameCn());
            res.setFieldType(item.getDtType());
            return res;
        }).collect(Collectors.toList());
        return JsonResult.success(resList);
    }

}

